package com.bingfabao.semephore;

import java.util.Random;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Semaphore;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/2/25  13:34
 * 描述:
 */

public class MySemeRun implements Runnable {

    private Semaphore semaphore;

    public MySemeRun(Semaphore semaphore) {
        this.semaphore = semaphore;
    }

    @Override
    public void run() {

        try {
            semaphore.acquire();

            for (int i=0;i<10;i++){
                System.out.println(Thread.currentThread().getName()+"====>"+i);
                Thread.sleep(1000);
            }

            semaphore.release();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
